#include <gtest/gtest.h>
#include <vector>
#include <algorithm>

using namespace ::std;

class Solution {
public:
    vector<vector<int>> threeSum(vector<int>& nums);
};

vector<vector<int>> Solution::threeSum(vector<int>& nums) {
    vector<vector<int>> result = {};
    sort(nums.begin(), nums.end());
    // size()函数返回的是无符号整型(long unsigned int)，所以如果返回值为0的话，-1会变成最大的整形
    if(nums.size() < 3) return result;
    for(int i = 0; i < nums.size() - 2; ++i) {
        for(int j = i + 1; j < nums.size() - 1; ++j) {
            for(int k = j + 1; k < nums.size(); ++k) {
                if(0 == nums[i] + nums[j] + nums[k]) result.push_back({nums[i], nums[j], nums[k]});
            }
        }
    }
    return result;
}

class ThreeSumCheck : public ::testing::Test {
public:
	class Solution solution;
};

TEST_F(ThreeSumCheck, testThreeSum_1) {
    vector<int> nums = {-1,0,1,2,-1,-4};
    vector<vector<int>> out = solution.threeSum(nums);
    EXPECT_TRUE(vector<int>({-1,-1,2}) == out[0]);
    EXPECT_TRUE(vector<int>({-1,0,1}) == out[1]);
    // EXPECT_TRUE(vector<vector<int>>({-1,-1,2}, {-1,0,1}) == solution.threeSum(nums));
}

TEST_F(ThreeSumCheck, testThreeSum_2) {
    vector<int> nums = {};
    vector<vector<int>> out = solution.threeSum(nums);
    EXPECT_TRUE(out.empty());
}

TEST_F(ThreeSumCheck, testThreeSum_3) {
    vector<int> nums = {0};
    vector<vector<int>> out = solution.threeSum(nums);
    EXPECT_TRUE(out.empty());
}

int main() {
	::testing::InitGoogleTest();
	return RUN_ALL_TESTS();
}
